import numpy as np
from sklearn.linear_model import Lasso
from sklearn.linear_model import SGDRegressor

X = 3 * np.random.rand(100, 1)
y = 5 + 4 * X + np.random.rand(100, 1)

lasso_l1 = Lasso(alpha=0.14, max_iter=30000)
lasso_l1.fit(X, y)
print("实际值:", 5 + 4 * 1.5)
print("预测值:", lasso_l1.predict([[1.5]]))
print("截距:", lasso_l1.intercept_)
print("系数:", lasso_l1.coef_)

regressor = SGDRegressor(penalty='l1', max_iter=3000)
regressor.fit(X, y.ravel())
print("预测值:", regressor.predict([[1.5]]))
print("截距:", regressor.intercept_)
print("系数:", regressor.coef_)
